function [num] = sd2dec(sd,r)
    neg_num_pos = find(sd < 0);
    len = length(sd);
    neg_vector = zeros(1,len);
    neg_vector(neg_num_pos) = sd(neg_num_pos);
    pos_vector = sd;
    pos_vector(neg_num_pos) = zeros(1,length(neg_num_pos));
    
    pos_num = 0;
    neg_num = 0;
    for i = len:-1:1,
       pos_num = pos_num + pos_vector(i)*r^(len-i); 
       neg_num = neg_num + neg_vector(i)*r^(len-i); 
    end
    
    num = pos_num + neg_num;
end
